<?php
 
$convert_toSpace = true;	// true if script should convert _ in folder names to spaces
$upperCaseWords = true;	// true if script should convert lowercase to initial caps
$topLevelName = "Inicio";		// name of home/root directory
 
// find index page in directory...
function MPBCDirIndex($dir) {
	$index = '';
	@$dir_handle = opendir($dir);
	if ($dir_handle) {
		while ($file = readdir($dir_handle)) {
			$test = substr(strtolower($file), 0, 6);
			if ($test == 'index.') {
				$index = $file;
				break;
				}
			}
		}
	return $index;
	}
 
// make clean array (trim entries and remove blanks)...
function MPBCTrimArray($array) {
	$clean = array();
	for ($n=0; $n<count($array); $n++) {
		$entry = trim($array[$n]);
		if ($entry != '') $clean[] = $entry;
		}
	return $clean;
	}
 
// function to prep string folder names if needed...
function MPBCFixNames($string) {
	global $convert_toSpace;
	global $upperCaseWords;
	if ($convert_toSpace) $string = str_replace('_', ' ', $string);
	if ($upperCaseWords) $string = ucwords($string);
	return $string;
	}
 
$server = (isset($_SERVER)) ? $_SERVER : $HTTP_SERVER_VARS;
 
$htmlRoot = (isset($server['DOCUMENT_ROOT'])) ? $server['DOCUMENT_ROOT'] : '';
if ($htmlRoot == '') $htmlRoot = (isset($server['SITE_HTMLROOT'])) ? $server['SITE_HTMLROOT'] : '';
 
$pagePath = (isset($server['PHP_SELF'])) ? $server['PHP_SELF'] : '';
if ($pagePath == '') $pagePath = (isset($server['PHP_SELF'])) ? $server['PHP_SELF'] : '';
 
$httpPath = ($htmlRoot != '/') ? str_replace($htmlRoot, '', $pagePath) : $pathPath;
 
$dirArray = explode('/', $httpPath);
if (!is_dir($htmlRoot.$httpPath)) $dirArray = array_slice($dirArray, 0, count($dirArray) - 1);
 
$linkArray = array();
$thisDir = '';
$baseDir = ($htmlRoot == '') ? '' : $htmlRoot;
for ($n=0; $n<count($dirArray); $n++) {
	$thisDir .= $dirArray[$n].'/';
	$thisIndex = MPBCDirIndex($htmlRoot.$thisDir);
	$thisText = ($n == 0) ? $topLevelName : MPBCFixNames($dirArray[$n]);
	$thisLink = ($thisIndex != '') ? '<a href="'.$thisDir.$thisIndex.'">'.$thisText.'</a>' : $thisText;
	if ($thisLink != '') $linkArray[] = $thisLink;
	}
 
$results = (count($linkArray) > 0) ? implode($linkArray) : '';
if ($results != '') print('<div class="breadcrumbs">'.$results.'</div>');
 
?>